//
//  TTTabBar.m
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/21.
//  Copyright © 2016年 陶路路. All rights reserved.
//

#import "TTTabBar.h"

@interface TTTabBar ()

@property (nonatomic,strong) UIButton * button;

@end
@implementation TTTabBar

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setUpTabBar];
    }
    
    return self;
}

-(void)setUpTabBar{
    
    self.button = [[UIButton alloc]init];
    [self.button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [self.button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    
    [self.button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [self.button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    
    [self addSubview:self.button];
    
}

-(void)layoutSubviews{
    
    [super layoutSubviews];
    
    CGFloat width = self.frame.size.width * 0.2;
    NSInteger index = 0;
    NSArray * buttonArray = self.subviews;
    for (int i = 0; i < buttonArray.count; i++) {
        
        if ([buttonArray[i] isKindOfClass:[NSClassFromString(@"UITabBarButton") class]]) {
            
            self.subviews[i].frame = CGRectMake(index * width, 0, width, self.frame.size.height);
            
            index++;
            
            if (index == 2) {
                
                self.button.frame = CGRectMake(index * width, 0, width, self.frame.size.height);
                
                index++;
                
            }
        }
    }
}
@end
